﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Arles.src.view;
using System.Windows.Forms;
using System.IO;
using ArlesInterfaces.Editor;

namespace Arles.src.utils
{
    public class ConfigFile : IConfigFile
    {
        //Private Members
        static ConfigFile handle;
        const string FileName = "resources/Config.xml";
        Attributes attributes;

        //Public Members


        public Attributes Attributes 
        {
            get { return attributes; }
        }

        public static IConfigFile Instance
        {
            get
            {
                if (handle == null)
                    handle = new ConfigFile();

                return handle;
            }
        }

        private ConfigFile()
        {
            attributes = new Attributes();

            //Lectura desde el fichero XML de proyecto
            XmlDocument xml = new XmlDocument();
            try
            {
                xml.Load(FileName);

                foreach (XmlNode node in xml.SelectNodes("/Arles/Config"))
                {
                    Attributes.LogType = node.ChildNodes[0].InnerText;
                    Attributes.UndoLimit = int.Parse(node.ChildNodes[1].InnerText);
                    Attributes.SaveLayout = bool.Parse(node.ChildNodes[2].InnerText);
                }
#if DEBUG
                Console.WriteLine("Fichero de configuración cargado correctamente");
#endif
            }
            catch (XmlException e)
            {
#if DEBUG
                Console.WriteLine("Fallo en la carga del fichero de configuración:" + e.ToString());
#endif
            }
        }

    }
}
